package Game;

public class Player {
	
	private static final Player[] players;
	
	static {
		PlayerID[] playerIDs = PlayerID.values();
		players = new Player[playerIDs.length];
		for (int i = 0; i < playerIDs.length; i++) {
			players[i] = new Player(playerIDs[i]);
		}
	}
	
	public static Player getPlayerByID(PlayerID id) {
		return getPlayerByID(id.id);
	}
	
	public static Player getPlayerByID(int id) {
		return players[id];
	}
	
	private String name;
	private int points;
	private Sign sign;
	private PlayerID id;
	
	private Player(PlayerID id) {
		this.id = id;
		points = 0;
		String n = IO.loadString(id.name() + "name");
		String s = IO.loadString(id.name() + "sign");
		if (n != null) {
			name = n;
		} else { 
			name = Strings.getString(id.name());
		}
		if (s != null) {
			sign = Sign.valueOf(s);
		} else {
			if (id == PlayerID.you) {
				sign = Sign.circle;
			} else {
				sign = Sign.cross;
			}
		}
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		IO.saveString(id.name() + "name", name);
		this.name = name;
	}

	public int getPoints() {
		return points;
	}

	public void addPoints() {
		this.points++;
	}

	public Sign getSign() {
		return sign;
	}

	public void setSign(Sign sign) {
		IO.saveString(id.name() + "sign", sign.name());
		this.sign = sign;
	}
	
	public PlayerID getID(){
		return id;
	}

	public enum PlayerID {
		
		you(0), opponent(1);
		
		public final int id;
		
		private PlayerID(int id) {
			this.id = id;
		}
		
	}
	
	public enum Sign {
		
		cross(0), circle(1);
		
		public final int id;
		
		private Sign(int id) {
			this.id = id;
		}
		
	}

}
